WebSocketClient.off   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 1
rs 10
c 0
b 0
f 0
cc 1
1
// Generated by dts-bundle-generator v9.5.1
2
3
declare namespace wsc {
4
	interface DataObject {
5
		[key: string]: any;
6
	}
7
	type WSEvent = "open" | "message" | "close" | "error" | "timeout";
8
	/** Minimal socket-like interface. */
9
	interface Socket {
10
		readyState: number;
11
		send(...any: any[]): void;
12
		close(): void;
13
		addEventListener: WebSocket["addEventListener"];
14
		removeEventListener: WebSocket["removeEventListener"];
15
	}
16
	type AsyncErrCode = Promise<number | null | {}>;
17
	type EventHandler = (e: any) => void;
18
	type DataPipe = (message: any) => any;
19
	type DataType = "json" | "string";
20
	interface Config {
21
		data_type: DataType;
22
		log(event: string, time?: number | null, message?: any): void;
23
		log(event: string, message?: any): void;
24
		timer: boolean;
25
		url: string;
26
		timeout: number;
27
		reconnect: number;
28
		lazy: boolean;
29
		socket: Socket | null;
30
		adapter: (host: string, protocols?: string[]) => Socket;
31
		encode: (key: string, message: any, config: Config) => any;
32
		decode: (rawMessage: any) => {
33
			[id_or_data_key: string]: string;
34
		};
35
		protocols: string[];
36
		pipes: DataPipe[];
37
		server: {
38
			id_key: string;
39
			data_key: string;
40
		};
41
		ping: {
42
			interval: number;
43
			content: any;
44
		};
45
	}
46
	type UserConfig = Partial<Config>;
47
	interface SendOptions {
48
		top: any;
49
		data_type: DataType;
50
	}
51
	interface Message {
52
		msg: any;
53
		ff(x: any): any;
54
		data_type: DataType;
55
		sent_time: number | null;
56
		timeout: NodeJS.Timeout;
57
	}
58
}
59
declare class WebSocketClient {
60
	private open;
61
	private ws;
62
	private forcibly_closed;
63
	private reconnect_timeout;
64
	private queue;
65
	private onReadyQueue;
66
	private onCloseQueue;
67
	private handlers;
68
	private config;
69
	private init_flush;
70
	private call;
71
	private log;
72
	private initSocket;
73
	private connect;
74
	get socket(): wsc.Socket | null;
75
	ready(): Promise<void>;
76
	on(event_name: wsc.WSEvent, handler: (data: any) => any, predicate?: (data: any) => boolean, raw?: boolean): wsc.EventHandler;
77
	off(event_name: wsc.WSEvent, handler: (data: any) => any, raw?: boolean): void;
78
	close(): wsc.AsyncErrCode;
79
	/**  .send(your_data) wraps request to server with {id: `hash`, data: `actually your data`},
80
	  returns a Promise that will be rejected after a timeout or
81
	  resolved if server returns the same signature: {id: `same_hash`, data: `response data`}.
82
	*/
83
	send<RequestDataType = any, ResponseDataType = any>(message_data: RequestDataType, opts?: wsc.SendOptions): Promise<ResponseDataType>;
84
	constructor(user_config?: wsc.UserConfig);
85
}
86
87
export {
88
	WebSocketClient as default,
89
};
90
91
export {};
92